// pages/mine/feedBack/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  inp_detail(e) {
    // console.log(e)
    let content = e.detail.value;
    this.setData({
      content: content,
    })
  },
  inp_contact(e) {
    // console.log(e)
    let contact = e.detail.value;
    this.setData({
      contact: contact,
    })
  },
  click_submit() {
    let content = this.data.content,
      images = this.data.tempFilePaths,
      contact = this.data.contact,
      base64 = this.data.base64;
    console.log('content+' + content + 'contact+' + contact)
    if (content && contact && base64) {
      this.submit(content, base64, contact)
    } else {
      wx.showModal({
        content: '问题和联系方式不能为空',
        showCancel: false,
        confirmText: '确定',
        confirmColor: '#cf9a57',
        success: function(e) {},
      })
    }

  },
  submit(content, images, contact) {
    wx.request({
      url: app.globalData.url + 'api/mine/question',
      data: {
        token: app.globalData.token,
        content: content,
        images: images,
        contact: contact,
      },
      method: 'POST',
      success: (e) => {
        console.log(e)
        wx.showModal({
          content: '您的问题已提交成功，客服将会在48小时内联系您',
          showCancel: false,
          confirmText: '确定',
          confirmColor: '#cf9a57',
          success: function(e) {
            if (e.confirm) {
              wx.navigateBack({
                delta: 1,
              })
            }
          },
        })
      },
    })
  },
  // 上传图片
  upload_img() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        // console.log(res)
        let tempFilePaths = res.tempFilePaths[0];
        wx.getFileSystemManager().readFile({
          filePath: res.tempFilePaths[0], //选择图片返回的相对路径
          encoding: 'base64', //编码格式
          success: res => { //成功的回调
            // console.log(res.data);
            let base64 = res.data;
            this.setData({
              base64: base64,
            })
          }
        })
        this.setData({
          tempFilePaths: tempFilePaths
        })
      }
    })
  },
  //删除
  click_del() {
    this.setData({
      tempFilePaths: '',
      base64:''
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})